package com.niiwoo.civet.user.service.duboo;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.niiwoo.civet.manage.trade.enums.UserInfoFieldTypeEnum;
import com.niiwoo.civet.snapdata.dto.request.InsertUserInfoUpdateRecordDetailDTO;
import com.niiwoo.civet.snapdata.dto.request.InsertUserInfoUpdateRecordReqDTO;
import com.niiwoo.civet.snapdata.service.UserInfoUpdateRecordDubboService;
import com.niiwoo.civet.trade.enums.TradeConfigEnum;
import com.niiwoo.civet.trade.service.configure.TradeConfigDubboService;
import com.niiwoo.civet.user.dao.entity.UserAreaDictionary;
import com.niiwoo.civet.user.dto.LinkManDubboInfoDTO;
import com.niiwoo.civet.user.dto.UserPersonalDubboInfoDTO;
import com.niiwoo.civet.user.dto.UserProfessionDubboInfoDTO;
import com.niiwoo.civet.user.dto.request.LoanDataAuthenticationRequestDTO;
import com.niiwoo.civet.user.dto.request.UpdateUserBasicInfIMRequestDTO;
import com.niiwoo.civet.user.dto.response.*;
import com.niiwoo.civet.user.enums.UserInfoUpdateOperTypeEnum;
import com.niiwoo.civet.user.enums.UserPersonalEnum;
import com.niiwoo.civet.user.service.ImDubboService;
import com.niiwoo.civet.user.service.UserCreditDubboService;
import com.niiwoo.civet.user.service.UserDataDubboService;
import com.niiwoo.civet.user.service.dataflow.UserProfessionInfoBackFlowDubboService;
import com.niiwoo.civet.user.service.local.TianchengDataService;
import com.niiwoo.civet.user.service.local.UserDataService;
import com.niiwoo.civet.user.service.local.UserIdentityService;
import com.niiwoo.civet.user.service.local.UserStatusService;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.provider.exception.BizException;
import com.niiwoo.tripod.tiancheng.request.common.RelationVerification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
 * @Author: wuke
 * @Description:
 * @Date: Created in 16:00 2017/11/8
 */
@Slf4j
@Service(version = "1.0.0")
public class UserDataDubboServiceImpl implements UserDataDubboService {

    @Autowired
    private TianchengDataService tianchengDataService;
    @Autowired
    private ImDubboService imDubboService;
    @Autowired
    private PrivacyMasks privacyMasks;
    @Autowired
    private UserStatusService userStatusService;
    @Autowired
    private UserDataService userDataService;
    @Autowired
    private UserIdentityService userIdentityService;


    @Reference(version = "1.0.0")
    private UserInfoUpdateRecordDubboService userInfoUpdateRecordDubboService;
    @Reference(version = "1.0.0")
    private TradeConfigDubboService tradeConfigDubboService;
    @Reference(version = "1.0.0")
    private UserProfessionInfoBackFlowDubboService userProfessionInfoBackFlowDubboService;
    @Reference(version = "1.0.0")
    private UserCreditDubboService userCreditService;


    @Override
    public UserPersonalDubboInfoDTO userPersonalInfo(String userId) {
        UserPersonalDubboInfoDTO userPersonalDubboInfoDTO = userDataService.userPersonalInfo(userId);
        if (userPersonalDubboInfoDTO == null) {
            return null;
        }
        //学历是否可以修改
        int limitMonth = 5;
        Map<String, String> tradeConfigMap = this.getEduUpdateLimitMonth();
        String limitMonthStr = tradeConfigMap.get(TradeConfigEnum.EDU_UPDATE_LIMIT_MONTH.getConfigKey());
        if (StringUtils.hasText(limitMonthStr)) {
            limitMonth = Integer.parseInt(limitMonthStr);
        }
        userPersonalDubboInfoDTO.setLimitMonth(limitMonth);
        userPersonalDubboInfoDTO.setCopyWritingHintsAddress(tradeConfigMap.get(TradeConfigEnum.COPYWRITINGHINTSADDRESS.getConfigKey()));
        userPersonalDubboInfoDTO.setCopyWritingHintsEmail(tradeConfigMap.get(TradeConfigEnum.COPYWRITINGHINTSEMAIL.getConfigKey()));
        userPersonalDubboInfoDTO.setEduIsAllowUpdate(this.getEduIsAllowUpdate(limitMonth, userPersonalDubboInfoDTO));

        return userPersonalDubboInfoDTO;
    }

    //获取学历修改限制月份与页面文案配置
    private Map<String, String> getEduUpdateLimitMonth() {
        Map<String, String> tradeConfigMap = null;
        try {
            tradeConfigMap = tradeConfigDubboService.selectTradeConfigByEmuns(Arrays.asList(
                    TradeConfigEnum.EDU_UPDATE_LIMIT_MONTH,
                    TradeConfigEnum.COPYWRITINGHINTSADDRESS,
                    TradeConfigEnum.COPYWRITINGHINTSEMAIL
            ));
            log.info("getEduUpdateLimitMonth.tradeConfigMap={}", JSON.toJSONString(tradeConfigMap));
        } catch (Exception e) {
            log.error("获取学历修改限制月份与页面文案配置错误", e.getMessage());
        }
        return tradeConfigMap;
    }

    // 判断是否允许修改学习
    private byte getEduIsAllowUpdate(int limitMonth, UserPersonalDubboInfoDTO userPersonalDubboInfoDTO) {
        //学历未认证或认证时间为空，则允许修改学历
        if (userPersonalDubboInfoDTO.getEducationAuthTime() == null ||
                UserPersonalEnum.EducationAuthStatusEnum.NO_AUTH.getStatus().byteValue() == userPersonalDubboInfoDTO.getEducationAuthStatus().byteValue()) {
            return UserPersonalEnum.EduIsAllowUpdateEnum.ALLOW.getType();
        }

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -limitMonth);
        if (cal.getTime().after(userPersonalDubboInfoDTO.getEducationAuthTime())) {
            return UserPersonalEnum.EduIsAllowUpdateEnum.ALLOW.getType();
        }
        return UserPersonalEnum.EduIsAllowUpdateEnum.NO_ALLOW.getType();
    }

    @Override
    public UserProfessionDubboInfoDTO userProfessionInfo(String userId) {
        UserProfessionDubboInfoDTO userInfoDTO = userDataService.userProfessionInfo(userId);
        if (userInfoDTO == null) {
            return null;
        }

        Map<String, String> tradeConfigMap = tradeConfigDubboService.selectTradeConfigByEmuns(Arrays.asList(
                TradeConfigEnum.COPYWRITINGHINTSOFFICEADDRESS,
                TradeConfigEnum.COPYWRITINGHINTSOFFICENAME,
                TradeConfigEnum.COPYWRITINGHINTSOFFICEPHONENUM
        ));

        userInfoDTO.setCopyWritingHintsOfficeAddress(tradeConfigMap.get(TradeConfigEnum.COPYWRITINGHINTSOFFICEADDRESS.getConfigKey()));
        userInfoDTO.setCopyWritingHintsOfficeName(tradeConfigMap.get(TradeConfigEnum.COPYWRITINGHINTSOFFICENAME.getConfigKey()));
        userInfoDTO.setCopyWritingHintsOfficePhoneNum(tradeConfigMap.get(TradeConfigEnum.COPYWRITINGHINTSOFFICEPHONENUM.getConfigKey()));
        return userInfoDTO;
    }

    @Override
    public void saveOrUpdateUserPersonalInfo(UserPersonalDubboInfoDTO userPersonalDubboInfoDTO) {
        log.info("saveOrUpdateUserPersonalInfo.userPersonalDubboInfoDTO={}", JSON.toJSONString(userPersonalDubboInfoDTO));
        UserPersonalDubboInfoDTO oldUserPersonalDubboInfoDTO = userDataService.userPersonalInfo(userPersonalDubboInfoDTO.getUserId());
        userDataService.saveOrUpdateUserPersonalInfo(userPersonalDubboInfoDTO);

        try {
            this.savePersonalInfoUpdateRecord(oldUserPersonalDubboInfoDTO, userPersonalDubboInfoDTO);
        } catch (Exception e) {
            log.error("saveOrUpdateUserPersonalInfo.savePersonalInfoUpdateRecord error", e);
        }

        // 个人信息天秤回流
        try {
            log.info("userProfessionInfoBackFlowDubboService.personalInfo userId={} start", userPersonalDubboInfoDTO.getUserId());
            CompletableFuture.runAsync(() -> userProfessionInfoBackFlowDubboService.personalInfo(userPersonalDubboInfoDTO.getUserId()));
            log.info("userProfessionInfoBackFlowDubboService.personalInfo userId={} end", userPersonalDubboInfoDTO.getUserId());
        } catch (Exception e) {
            log.info("userProfessionInfoBackFlowDubboService.personalInfo userId={} error", userPersonalDubboInfoDTO.getUserId());
        }
    }

    //如果从未保存过，则不做处理
    private void savePersonalInfoUpdateRecord(UserPersonalDubboInfoDTO oldUserInfoDTO, UserPersonalDubboInfoDTO newUserInfoDTO) {
        String userId = newUserInfoDTO.getUserId();
        if (oldUserInfoDTO == null) {
            return;
        }
        UserInfoUpdateOperTypeEnum userInfoUpdateOperTypeEnum = newUserInfoDTO.getUserInfoUpdateOperTypeEnum();
        userInfoUpdateOperTypeEnum = (userInfoUpdateOperTypeEnum == null ? UserInfoUpdateOperTypeEnum.APP_USER : userInfoUpdateOperTypeEnum);
        newUserInfoDTO.setUserInfoUpdateOperTypeEnum(userInfoUpdateOperTypeEnum);

        Date oldDataCreateTime = oldUserInfoDTO.getCreateTime();
        List<InsertUserInfoUpdateRecordDetailDTO> detailList = new ArrayList<>();
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getLivingProvince(), newUserInfoDTO.getLivingProvince(), oldDataCreateTime, UserInfoFieldTypeEnum.LIVING_PROVINCE, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getLivingCity(), newUserInfoDTO.getLivingCity(), oldDataCreateTime, UserInfoFieldTypeEnum.LIVING_CITY, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getLivingArea(), newUserInfoDTO.getLivingArea(), oldDataCreateTime, UserInfoFieldTypeEnum.LIVING_AREA, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getLivingAddress(), newUserInfoDTO.getLivingAddress(), oldDataCreateTime, UserInfoFieldTypeEnum.LIVING_ADDRESS, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, String.valueOf(oldUserInfoDTO.getMaritalStatus()), String.valueOf(newUserInfoDTO.getMaritalStatus()), oldDataCreateTime, UserInfoFieldTypeEnum.MARITAL_STATUS, detailList);
        this.initLinkManInfoUpdateRecordDetailList(userId, newUserInfoDTO.getLinkManInfoList(), oldUserInfoDTO.getLinkManInfoList(), detailList, oldDataCreateTime);
        log.info("savePersonalInfoUpdateRecord.userId={},detailList={}", userId, JSON.toJSONString(detailList));

        if (!CollectionUtils.isEmpty(detailList)) {
            InsertUserInfoUpdateRecordReqDTO reqDTO = new InsertUserInfoUpdateRecordReqDTO();
            reqDTO.setUserInfoUpdateOperType(newUserInfoDTO.getUserInfoUpdateOperTypeEnum().getType());
            reqDTO.setDetailList(detailList);
            userInfoUpdateRecordDubboService.insertUserInfoUpdateRecord(reqDTO);
        }
    }

    private void initLinkManInfoUpdateRecordDetailList(String userId, List<LinkManDubboInfoDTO> newLinkManInfoList, List<LinkManDubboInfoDTO> oldLinkManInfoList, List<InsertUserInfoUpdateRecordDetailDTO> detailList, Date oldDataCreatTime) {
        String oldLinkManInfoMapListJSONString = this.linkManInfoListConvertToJSONString(oldLinkManInfoList);
        String newLinkManInfoMapListJSONString = this.linkManInfoListConvertToJSONString(newLinkManInfoList);
        this.initUserInfoUpdateRecordDetailList(userId, oldLinkManInfoMapListJSONString, newLinkManInfoMapListJSONString, oldDataCreatTime, UserInfoFieldTypeEnum.LINKMAN_INFO, detailList);
    }

    //将联系人列表转化为JSON字符串
    private String linkManInfoListConvertToJSONString(List<LinkManDubboInfoDTO> linkManInfoList) {
        List<Map<String, Object>> linkManInfoMapList = new ArrayList<Map<String, Object>>();
        if (!CollectionUtils.isEmpty(linkManInfoList)) {
            for (LinkManDubboInfoDTO link : linkManInfoList) {
                Map<String, Object> linkMap = new HashMap();
                linkMap.put("name", link.getName());
                linkMap.put("mobileNo", privacyMasks.encryptPrivacy(link.getMobileNo()));
                linkMap.put("relation", link.getRelation());
                linkMap.put("orderNo", link.getOrderNo());
                linkManInfoMapList.add(linkMap);
            }
        }
        String linkManInfoMapListJSONString = CollectionUtils.isEmpty(linkManInfoMapList) ? null : JSONArray.toJSONString(linkManInfoMapList);
        return linkManInfoMapListJSONString;
    }

    private void initUserInfoUpdateRecordDetailList(String userId, String oldValue, String newValue, Date oldDataCreateTime, UserInfoFieldTypeEnum dataTypeEnum, List<InsertUserInfoUpdateRecordDetailDTO> detailList) {
        if (!Objects.equals(oldValue, newValue)) {
            InsertUserInfoUpdateRecordDetailDTO detailDTO = new InsertUserInfoUpdateRecordDetailDTO();
            detailDTO.setUserId(userId);
            detailDTO.setDataType(dataTypeEnum.getValue());
            detailDTO.setValue(newValue);
            detailDTO.setOldValue(oldValue);
            detailDTO.setUserType((byte) 1);
            detailDTO.setOldUserType(UserInfoUpdateOperTypeEnum.APP_USER.getType());
            detailDTO.setOldDataCreatTime(oldDataCreateTime);
            detailList.add(detailDTO);
        }
    }

    @Override
    public void saveOrUpdateUserProfessionInfo(UserProfessionDubboInfoDTO userProfessionDubboInfoDTO) {
        log.info("saveOrUpdateUserProfessionInfo.userProfessionDubboInfoDTO={}", JSON.toJSONString(userProfessionDubboInfoDTO));
        UserProfessionDubboInfoDTO oldUserProfessionDubboInfoDTO = userDataService.userProfessionInfo(userProfessionDubboInfoDTO.getUserId());
        userDataService.saveOrUpdateUserProfessionInfo(userProfessionDubboInfoDTO);
        try {
            this.saveProfessionInfoUpdateRecord(oldUserProfessionDubboInfoDTO, userProfessionDubboInfoDTO);
        } catch (Exception e) {
            log.error("saveOrUpdateUserProfessionInfo.saveProfessionInfoUpdateRecord error", e);
        }

        // 推送职业信息至IM系统
        this.pushUserProfessionInfoToIM(oldUserProfessionDubboInfoDTO, userProfessionDubboInfoDTO);
        // 职业信息天秤回流
        try {
            log.info("userProfessionInfoBackFlowDubboService.professionInfo userId={} start", userProfessionDubboInfoDTO.getUserId());
            CompletableFuture.runAsync(() -> userProfessionInfoBackFlowDubboService.professionInfo(userProfessionDubboInfoDTO.getUserId()));
            log.info("userProfessionInfoBackFlowDubboService.professionInfo userId={} end", userProfessionDubboInfoDTO.getUserId());
        } catch (Exception e) {
            log.info("userProfessionInfoBackFlowDubboService.professionInfo userId={} error", userProfessionDubboInfoDTO.getUserId());
        }
    }

    private void pushUserProfessionInfoToIM(UserProfessionDubboInfoDTO oldUserInfoDTO, UserProfessionDubboInfoDTO newUserInfoDTO) {
        try {
            String newCompanyName = newUserInfoDTO.getCompanyName();
            String newPosition = newUserInfoDTO.getPosition();
            String newCompanyArea = newUserInfoDTO.getCompanyArea();

            if (oldUserInfoDTO != null
                    && Objects.equals(oldUserInfoDTO.getCompanyName(), newCompanyName)
                    && Objects.equals(oldUserInfoDTO.getPosition(), newPosition)
                    && Objects.equals(oldUserInfoDTO.getCompanyArea(), newCompanyArea)) {
                return;
            }
            UpdateUserBasicInfIMRequestDTO request = new UpdateUserBasicInfIMRequestDTO();
            request.setGuid(newUserInfoDTO.getUserId());
            request.setCompany(newCompanyName);
            request.setOccupation(newPosition);
            request.setArea(newCompanyArea);
            log.info("pushUserProfessionInfoToIM.userId={},request={}", newUserInfoDTO.getUserId(), JSON.toJSONString(request));
            imDubboService.updateUserBasicInfIM(request);
        } catch (Exception e) {
            log.error("pushUserProfessionInfoToIM.userId={} error", newUserInfoDTO.getUserId(), e);
        }
    }

    private void saveProfessionInfoUpdateRecord(UserProfessionDubboInfoDTO oldUserInfoDTO, UserProfessionDubboInfoDTO newUserInfoDTO) {
        String userId = newUserInfoDTO.getUserId();
        if (oldUserInfoDTO == null) { //如果从未保存过，则不做处理
            return;
        }
        UserInfoUpdateOperTypeEnum userInfoUpdateOperTypeEnum = newUserInfoDTO.getUserInfoUpdateOperTypeEnum();
        userInfoUpdateOperTypeEnum = (userInfoUpdateOperTypeEnum == null ? UserInfoUpdateOperTypeEnum.APP_USER : userInfoUpdateOperTypeEnum);
        newUserInfoDTO.setUserInfoUpdateOperTypeEnum(userInfoUpdateOperTypeEnum);

        Date oldCreateTime = oldUserInfoDTO.getCreateTime();
        List<InsertUserInfoUpdateRecordDetailDTO> detailList = new ArrayList<>();
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyName(), newUserInfoDTO.getCompanyName(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_NAME, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyPhone(), newUserInfoDTO.getCompanyPhone(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_PHONE, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getDepartment(), newUserInfoDTO.getDepartment(), oldCreateTime, UserInfoFieldTypeEnum.DEPARTMENT, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getPosition(), newUserInfoDTO.getPosition(), oldCreateTime, UserInfoFieldTypeEnum.POSITION, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyProvince(), newUserInfoDTO.getCompanyProvince(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_PROVINCE, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyCity(), newUserInfoDTO.getCompanyCity(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_CITY, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyArea(), newUserInfoDTO.getCompanyArea(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_AREA, detailList);
        this.initUserInfoUpdateRecordDetailList(userId, oldUserInfoDTO.getCompanyAddress(), newUserInfoDTO.getCompanyAddress(), oldCreateTime, UserInfoFieldTypeEnum.COMPANY_ADDRESS, detailList);

        log.info("saveProfessionInfoUpdateRecord.userId={},detailList={}", userId, JSON.toJSONString(detailList));
        if (!CollectionUtils.isEmpty(detailList)) {
            InsertUserInfoUpdateRecordReqDTO reqDTO = new InsertUserInfoUpdateRecordReqDTO();
            reqDTO.setDetailList(detailList);
            reqDTO.setUserInfoUpdateOperType(newUserInfoDTO.getUserInfoUpdateOperTypeEnum().getType());
            userInfoUpdateRecordDubboService.insertUserInfoUpdateRecord(reqDTO);
        }
    }

    /**
     * 根据区域名称查询区域code 模糊匹配  areaName%
     *
     * @param areaName
     * @return
     */
    public String selectAreaCodeByAreaName(String areaName) {
        return userDataService.selectAreaCodeByAreaName(areaName);
    }

    /**
     * 根据areaName 查询areaCode与parentCode,结果可能会有多条 如南山区
     *
     * @param areaName
     * @return
     */
    public List<Map<String, String>> selectAreaCodeAndParentCodeByAreaName(String areaName) {
        return userDataService.selectAreaCodeAndParentCodeByAreaName(areaName);
    }

    /**
     * 用户信息检查（基本信息、个人信息、职业信息、账户）
     *
     * @param userId
     * @return
     */
    public UserInfoCheckResposeDTO userInfoCheck(String userId) {
        return userDataService.userInfoCheck(userId);
    }

    @Override
    public List<RelationVerificationDTO> getRelationVerification(String userId) {
        List<RelationVerificationDTO> relationVerificationDTOList = new ArrayList<RelationVerificationDTO>();
        List<RelationVerification> relationVerificationList = tianchengDataService.getRelationVerification(userId);
        for (RelationVerification relationVerification : relationVerificationList) {
            RelationVerificationDTO relationVerificationDTO = new RelationVerificationDTO();
            relationVerificationDTO.setRelation_name(relationVerification.getRelation_name());
            relationVerificationDTO.setRelation_phone(relationVerification.getRelation_phone());

            relationVerificationDTOList.add(relationVerificationDTO);
        }

        return relationVerificationDTOList;
    }

    @Override
    public List<UserAreaDictionaryDTO> selectFastBorrowAccreditCity(List<String> areaCode) {
        List<UserAreaDictionary> dictionaryList = userDataService.selectFastBorrowAccreditCity(areaCode);
        List<UserAreaDictionaryDTO> dictionaryDTOList = new ArrayList<>();
        for (UserAreaDictionary userAreaDictionary : dictionaryList) {
            UserAreaDictionaryDTO dictionaryDTO = new UserAreaDictionaryDTO();
            dictionaryDTO.setAreaCode(userAreaDictionary.getAreaCode());
            dictionaryDTO.setAreaName(userAreaDictionary.getAreaName());
            dictionaryDTO.setParentCode(userAreaDictionary.getParentCode());
            dictionaryDTOList.add(dictionaryDTO);
        }
        return dictionaryDTOList;
    }

    public String selectAreaNameByAreaCode(String areaCode) {
        return userDataService.selectAreaNameByAreaCode(areaCode);
    }

    @Override
    public LoanDataAuthenticationResponseDTO loanDataAuthentication(LoanDataAuthenticationRequestDTO requestDTO) {
        log.info("getIncreaseTheLoanAmountResponseList LoanDataAuthenticationRequestDTO={}", JSON.toJSON(requestDTO));

        List<TradeConfigEnum> enumList = new ArrayList<>();
        enumList.add(TradeConfigEnum.MOBILESERVICEPROVIDERPWDAUTHORIZEDPERIOD);  // 手机服务商密码授权期限配置
        enumList.add(TradeConfigEnum.IDCARDEXPIRYDATEPERIOD);                    // 距离身份证有效期截止日配置
        enumList.add(TradeConfigEnum.OCRSCANIDCARDSWITCH);                       // OCR扫描身份证开关1开启0关闭
        enumList.add(TradeConfigEnum.EDUCATIONQUALIFICATIONPERIOD);              // 学历认证期限配置
        enumList.add(TradeConfigEnum.JINGDONGAUTHPERIOD);                        // 京东认证期限配置
        enumList.add(TradeConfigEnum.CREDITCARDCERTIFICATIONPERIOD);             // 信用卡认证期限配置
        enumList.add(TradeConfigEnum.SOCIALSECURITYEXPIRYDATESETTINGS);          // 社保有效期设置
        enumList.add(TradeConfigEnum.TAOBAOAUTHPERIOD);          				 // 淘宝认证期限设置

        Map<String, String> tradeConfig = tradeConfigDubboService.selectTradeConfigByEmuns(enumList);
        if (CollectionUtils.isEmpty(tradeConfig)) {
            throw new BizException("USR10037");
        }

        // 手机服务商密码授权期限配置
        requestDTO.setMobileServicePeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.MOBILESERVICEPROVIDERPWDAUTHORIZEDPERIOD.getConfigKey())));
        // 距离身份证有效期截止日配置
        requestDTO.setIdCardExpiryDatePeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.IDCARDEXPIRYDATEPERIOD.getConfigKey())));
        // OCR扫描身份证开关1开启0关闭
        requestDTO.setOcrScanSwitch(Byte.valueOf(tradeConfig.get(TradeConfigEnum.OCRSCANIDCARDSWITCH.getConfigKey())));
        // 学历认证期限配置
        requestDTO.setEducationQualificationPeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.EDUCATIONQUALIFICATIONPERIOD.getConfigKey())));
        // 京东认证期限配置
        requestDTO.setJingdongAuthPeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.JINGDONGAUTHPERIOD.getConfigKey())));
        // 信用卡认证期限配置
        requestDTO.setCreditCardPeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.CREDITCARDCERTIFICATIONPERIOD.getConfigKey())));
        // 社保有效期设置
        requestDTO.setSocialSecurityPeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.SOCIALSECURITYEXPIRYDATESETTINGS.getConfigKey())));
        // 淘宝认证期限配置
        requestDTO.setTaobaoAuthPeriod(Integer.parseInt(tradeConfig.get(TradeConfigEnum.TAOBAOAUTHPERIOD.getConfigKey())));

        return userStatusService.loanDataAuthentication(requestDTO);
    }

    @Override
    public LoanConsumeInfoResponseDTO selectLoanConsumeInfo(String borrowUserId) {
        return userDataService.selectLoanConsumeInfo(borrowUserId);
    }
}
